home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 5.2 KB | 166 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWClustr.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWCLUSTR_H
- #include "FWClustr.h"
- #endif
-
- #ifndef FWRADIOB_H
- #include "FWRadioB.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgadgts
- #endif
-
- FW_DEFINE_CLASS_M1(FW_CRadioCluster, FW_CGadget)
-
- //========================================================================================
- // CLASS FW_CRadioCluster
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioCluster::FW_CRadioCluster
- //----------------------------------------------------------------------------------------
-
- FW_CRadioCluster::FW_CRadioCluster(Environment* ev,
- FW_CView* container, ODID id,
- const FW_CRect& bounds,
- const FW_CString& label,
- ODID buttonInitiallyOn) :
- FW_CGadget(ev, container, id, bounds),
- fLabel(label),
- fConnection(this),
- fButtonOnId(buttonInitiallyOn)
- {
- fConnection.Connect();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioCluster::~FW_CRadioCluster
- //----------------------------------------------------------------------------------------
-
- FW_CRadioCluster::~FW_CRadioCluster()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioCluster::GadgetAdopted
- //----------------------------------------------------------------------------------------
- // *LSD2 can only add button views to Radio Cluster
- void FW_CRadioCluster::ViewAdded(Environment* ev, FW_CGadget *gadget)
- {
- FW_CRadioButton* button = FW_DYNAMIC_CAST(FW_CRadioButton, gadget);
- FW_ASSERT(button);
-
- button->SetState(ev, button->GetIdentifier(ev) == fButtonOnId ? 1 : 0);
-
- FW_CInterest interest(button, button->GetButtonPressedNotificationToken(ev));
- fConnection.AddInterest(interest);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioCluster::GadgetRemoved
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioCluster::ViewRemoved(Environment* ev, const FW_CGadget& gadget)
- {
- FW_CRadioButton* button = FW_DYNAMIC_CAST(FW_CRadioButton, &gadget);
- FW_ASSERT(button);
-
- FW_CInterest interest(button, button->GetButtonPressedNotificationToken(ev));
- fConnection.RemoveInterest(interest);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioCluster::SetButtonOn
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioCluster::SetButtonOn(Environment* ev, ODID buttonOnId)
- {
- FW_CViewIterator iter(ev, this);
- for (FW_CView* gadget = (FW_CView*)iter.First(ev); iter.IsNotComplete(ev); gadget = (FW_CView*)iter.Next(ev))
- {
- FW_CRadioButton* button = FW_DYNAMIC_CAST(FW_CRadioButton, gadget);
- FW_ASSERT(button);
-
- if (button->GetIdentifier(ev) == buttonOnId && !button->GetState(ev))
- {
- button->SetState(ev, TRUE);
- button->Invalidate(ev);
- }
- else if (button->GetState(ev))
- {
- button->SetState(ev, FALSE);
- button->Invalidate(ev);
- }
- }
-
- fButtonOnId = buttonOnId;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioCluster::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioCluster::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- //const FW_CPoint kLabelPosition(ff(16), ff(0));
-
- // ----- Draw the label
-
- //FW_CTextShape::RenderText(gc, fLabel, kLabelPosition, FW_STextAlignment());
-
- // ----- Draw the frame
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRadioCluster::HandleNotification
- //----------------------------------------------------------------------------------------
-
- void FW_CRadioCluster::HandleNotification(const FW_CNotification& notification)
- {
- Environment* ev = somGetGlobalEnvironment();
-
- FW_CRadioButton* buttonPressed = FW_DYNAMIC_CAST(FW_CRadioButton, notification.GetNotifier());
- FW_ASSERT(buttonPressed);
-
- // Turn all but the just pressed button off
-
- FW_CViewIterator iter(ev, this);
- for (FW_CView* gadget = (FW_CView*)iter.First(ev); iter.IsNotComplete(ev);
- gadget = (FW_CView*)iter.Next(ev))
- {
- FW_CRadioButton* button = FW_DYNAMIC_CAST(FW_CRadioButton, gadget);
- FW_ASSERT(button);
-
- if (button != buttonPressed && button->GetState(ev))
- {
- FW_CViewContext gc(ev, button, GetFrame(ev)->GetActiveFacet(ev));
- button->SetState(ev, gc, FALSE);
- }
- }
-
- fButtonOnId = buttonPressed->GetIdentifier(ev);
- }
-